package sk.vasicek.drinkmanager.domain;

import java.util.ArrayList;

import sk.vasicek.drinkmanager.activity.DrinkMapDetailActivity;



import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class LocationItemizedOverlay extends ItemizedOverlay {

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	public LocationItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}

	public LocationItemizedOverlay(Drawable defaultMarker, Context context) {
		this(defaultMarker);
		mContext = context;
	}

	@Override
	protected OverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		OverlayItem item = mOverlays.get(index);
		 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		 dialog.setTitle(item.getTitle());
		 dialog.setMessage(item.getSnippet());
		 dialog.show();
//		Intent intent = new Intent(mContext, DrinkMapDetailActivity.class);
//
//		if (item.getTitle() != null && !"".equals(item.getTitle())) {
//			intent.putExtra(DrinkPoint.POINT_TITLE, item.getTitle());
//		}
//		if (item.getSnippet() != null && !"".equals(item.getSnippet())) {
//			intent.putExtra(DrinkPoint.POINT_SNIPPET, item.getSnippet());
//		}
//		mContext.startActivity(intent);
		return true;
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}
}
